package presenter.rename;

import main.InputBean;
import utils.FileBean;
import presenter.record.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;

/**
 * 重命名三星、华为、锤子手机录屏的文件
 * 锤子手机格式：Screenrecord-2022-05-14-22-41-44-051.mp4
 * 三星手机格式：Screen_Recording_20220212-221952.mp4
 * 三星手机格式2：Screen_Recording_20220921_224846.mp4
 * 三星手机格式3：Screen_Recording_20221001_190245_One UI Home.mp4
 * 华为P40格式：SVID_20221101_191153_4.mp4
 * 枞阳监控：1733904137083_0_5053493991_20241206142100_20241206142203.mp4
 * 最终格式：20220514-224144.mp4
 */
public class ScreenRecorderImpl implements IReNamer {
    private static final List<IRecorder> patterns = new ArrayList<>();

    static {
        patterns.add(new SmartisanRecorderImpl());//锤子手机
        patterns.add(new SamsungRecorderImpl());//三星手机
        patterns.add(new SamsungRecorder2Impl());//三星手机，第二种命名格式
        patterns.add(new SamsungRecorder3Impl());//三星手机，第三种命名格式
        patterns.add(new HuaweiRecorderImpl());//华为手机,P40格式
        patterns.add(new HomeRecImpl());//枞阳监控
        patterns.add(new HKFRecImpl());//海康威视-正面
        patterns.add(new HKRRecImpl());//海康威视-背面
        patterns.add(new HKOneRecImpl());//海康威视-单个-正常
        patterns.add(new HKEventRecImpl());//海康威视-单个-事件
    }

    @Override
    public boolean needReName(InputBean info, FileBean bean) {
        try {
            for (IRecorder recorder : patterns) {
                if (recorder.pattern().matcher(bean.name()).find()) {
                    return true;
                }
            }
        } catch (Exception ex) {

        }
        return false;
    }

    @Override
    public void reName(InputBean info,FileBean bean, Map<String, String> container) {
        try {
            for (IRecorder recorder : patterns) {
                Matcher matcher = recorder.pattern().matcher(bean.name());
                if (matcher.find()) {
                    container.put(bean.path(), recorder.rename(bean, matcher));
                    break;
                }
            }
        } catch (Exception ex) {
            //ignore
        }
    }
}
